package com.chenfan.mcn.model.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.chenfan.mcn.enums.DiscountApprovalEnum;
import com.chenfan.mcn.enums.ApprovalStatusEnum;
import com.chenfan.common.extension.validation.groups.Add;
import com.chenfan.common.extension.validation.groups.Modify;
import lombok.Data;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * 折扣审批单列表展示
 * @author lizhejin
 */
@Data
@ApiIgnore
public class DiscountApprovalVO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键id
     */
    @NotNull(message = "主键不能为空", groups = Modify.class)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 审批单编号
     */
    @Excel(name = "审批单号")
    private String discountCode;

    /**
     * 优惠类型:0_单笔优惠，1_年度优惠
     */
    @NotNull(message = "优惠类型不能为空", groups = {Add.class, Modify.class})
    private Integer approvalType;

    /**
     * 客户id
     */
    @NotNull(message = "客户信息不能为空", groups = {Add.class, Modify.class})
    private Long customerId;

    /**
     * 审批状态:0_待提交, 1_审批中, 2_审批通过, 3_审批拒绝, 4_已撤回
     */
    private Integer approvalStatus;

    /**
     * 合同主体(数据字典)
     */
    @NotBlank(message = "合同主体不能为空", groups = {Add.class, Modify.class})
    @Excel(name = "我司合同主体", orderNum = "8")
    private String contractSubject;

    /**
     * 是否签订年框合同
     */
    @NotNull(message = "是否签订年框合同不能为空", groups = {Add.class, Modify.class})
    @Excel(name = "是否签订年框合同", orderNum = "6", replace = {"否_false", "是_true", "_null"})
    private Boolean yearDiscountStatus;

    /**
     * 合同金额(单笔优惠时必填)
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private BigDecimal contractAmount;

    /**
     * 时效开始时间
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String startDate;

    /**
     * 失效结束时间
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String endDate;

    /**
     * 申请描述
     */
    @Excel(name = "申请理由", orderNum = "9")
    @NotBlank(message = "申请描述", groups = {Add.class, Modify.class})
    private String description;

    /**
     * 备注
     */
    @Excel(name = "备注", orderNum = "12")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String remark;

    /**
     * 返点类型(单笔优惠时必填)(数据字典)
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String rebateType;

    /**
     * 返点比例(单笔优惠时必填)
     */
    @Excel(name = "返点比例", orderNum = "17", numFormat = "#.##", suffix = "%")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private BigDecimal rebateRate;

    /**
     * 折扣比例(单笔优惠时必填)
     */
    @Excel(name = "折扣比例", orderNum = "18", numFormat = "#.##", suffix = "折")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private BigDecimal discountRate;

    /**
     * 优惠形式:0_仅频台返点,1_年度优惠含平台返点,2_年度优惠不含平台返点,3_仅年度优惠
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer discountType;

    /**
     * 是否含直播全案
     */
    @Excel(name = "是否直播全案", orderNum = "16", replace = {"否_false", "是_true", "_null"})
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Boolean liveBroadcastStatus;

    /**
     * 创建时间
     */
    @Excel(name = "创建时间", orderNum = "14", format = "yyyy/MM/dd HH:mm:ss")
    private Date createDate;

    /**
     * 创建人id
     */
    private Long createBy;

    /**
     * 创建人
     */
    @Excel(name = "创建人", orderNum = "13")
    private String createName;

    /**
     * 修改时间 (刷数据时注意改字段，不要影响业务单据修改时间)
     */
    private Date updateDate;

    /**
     * 修改人id
     */
    private Long updateBy;

    /**
     * 修改人
     */
    private String updateName;

    /**
     * 删除标识
     */
    private Integer isDelete;

    /**
     * 部门id
     */
    private Long departmentId;

    /**
     * 公司id
     */
    private Long companyId;

    /**
     * 租户id
     */
    private Long tenantId;

    /**
     * 附件
     */
    private String enclosure;

    @Excel(name = "生效状态", replace = {"未生效_false", "已生效_true"}, orderNum = "1")
    private Boolean isActive;

    @Excel(name = "优惠类型", orderNum = "3")
    private String approvalTypeName;

    @Excel(name = "审批状态", orderNum = "2")
    private String statusName;

    @Excel(name = "优惠形式", orderNum = "15")
    private String discountTypeName;

    private String flowStatusName;

    @Excel(name = "客户名称", orderNum = "5")
    private String customerName;

    @Excel(name = "所属部门", orderNum = "4")
    private String departmentName;

    @Excel(name = "年度优惠", orderNum = "19", width = 70)
    private String rangeInfo;

    @Excel(name = "平台下单返点优惠", orderNum = "20", width = 50)
    private String rebateInfo;

    private String contractSubjectName;

    @Excel(name = "返点类型", orderNum = "7")
    private String rebateTypeName;

    /**
     * 时效开始时间
     */
    @Excel(name = "时效开始时间", orderNum = "10", format = "yyyy/MM/dd HH:mm:ss")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date exportStartDate;

    /**
     * 失效结束时间
     */
    @Excel(name = "时效结束时间", orderNum = "11", format = "yyyy/MM/dd HH:mm:ss")
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date exportEndDate;

    /**
     * 流程id
     */
    private Long flowId;

    public String getStatusName() {
        if (Objects.nonNull(getApprovalStatus())) {
            return ApprovalStatusEnum.getStatusName(getApprovalStatus());
        }
        return null;
    }

    public String getApprovalTypeName() {
        if (Objects.nonNull(getApprovalType())) {
            return DiscountApprovalEnum.getStatusName("approvalType", getApprovalType());
        }
        return null;
    }

    public String getDiscountTypeName() {
        if (Objects.nonNull(getDiscountType())) {
            return DiscountApprovalEnum.getStatusName("discountType", getDiscountType());
        }
        return null;
    }

    /**
     * 我司签约主体id
     */
    private Long contractingId;
}
